package com.fy.market.strategy.model.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

/**
 * 规则类型枚举
 */
@Getter
@AllArgsConstructor
public enum RuleModelTypeEnum {

    /**
     * 抽奖前规则
     */
    BEFORE_LOTTERY(1, "抽奖前规则"),

    /**
     * 抽奖中规则
     */
    DURING_LOTTERY(2, "抽奖中规则"),

    /**
     * 抽奖后规则
     */
    AFTER_LOTTERY(3, "抽奖后规则");

    private final Integer code;
    private final String info;

    /**
     * 根据code获取枚举
     *
     * @param code 类型码
     * @return 规则类型枚举
     */
    public static RuleModelTypeEnum of(Integer code) {
        if (code == null) {
            return null;
        }
        for (RuleModelTypeEnum ruleModelTypeEnum : values()) {
            if (ruleModelTypeEnum.getCode().equals(code)) {
                return ruleModelTypeEnum;
            }
        }
        return null;
    }

    /**
     * 根据info获取枚举
     *
     * @param info 类型信息
     * @return 规则类型枚举
     */
    public static RuleModelTypeEnum ofInfo(String info) {
        if (info == null) {
            return null;
        }
        return Arrays.stream(values())
                .filter(ruleModelTypeEnum -> ruleModelTypeEnum.getInfo().equals(info))
                .findFirst()
                .orElse(null);
    }
}